package com.example.mmw.guidepro.activity;

import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.mmw.guidepro.R;
import com.example.mmw.guidepro.bean.WeatherInfo;
import com.example.mmw.guidepro.listener.WeatherListener;
import com.example.mmw.guidepro.mode.WeatherMode;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;

public class MainActivity extends AppCompatActivity implements View.OnClickListener,WeatherListener {
    EditText editCityNumber;
    Button button_CH, button_51;
    TextView textCityName, textTemp;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    void initView() {//初始化控件}
        editCityNumber = (EditText) findViewById(R.id.edit_citNumber);
        button_CH = (Button) findViewById(R.id.button_ch);
        button_51 = (Button) findViewById(R.id.button_51);
        textCityName = (TextView) findViewById(R.id.text_cityname);
        textTemp = (TextView) findViewById(R.id.text_temp);
        button_CH.setOnClickListener(this);
        button_51.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button_ch:
                WeatherMode mode=new WeatherMode();
                mode.getWeather(editCityNumber.getText().toString(),this);
                break;
            case R.id.button_51:
                ////////////
                break;
        }
    }


    @Override
    public void onResponse(WeatherInfo WeatherInfo) {
        textCityName.setText(WeatherInfo.getCity());
        textTemp.setText(WeatherInfo.getTemp());

    }

    @Override
    public void onFailure(String msg) {
        textCityName.setText("获取失败");
        textTemp.setText("获取失败");
    }
}
